﻿using SocketServer.WebSocketAction;
using System;
using System.Collections.Generic;
namespace SocketServer.SocketAttribute
{
    /// <summary>
    /// 过滤器 将ServerAction的IsEnd改为true表示结束执行方法
    /// </summary>
    /// <remarks>
    /// 类上特性执行优先级1 方法特性执行优先级2
    /// </remarks>
    public class WebSocketFilterAttribute : Attribute
    {
        /// <summary>
        /// 生成方法需要参数前触发(执行顺序1)
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnAuthorization(IWebSocketServerAction ServerAction)
        {
            
        }

        /// <summary>
        /// 方法执行前触发(执行顺序2)
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnActionExecuting(IWebSocketServerAction ServerAction)
        {

        }

        /// <summary>
        /// 方法执行后触发(执行顺序3)
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnActionExecuted(IWebSocketServerAction ServerAction)
        {

        }

        /// <summary>
        /// 结果返回前触发(执行顺序4)
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnResultExecuting(IWebSocketServerAction ServerAction)
        {

        }

        /// <summary>
        /// 结果返回后触发(执行顺序5)
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnResultExecuted(IWebSocketServerAction ServerAction)
        {

        }

        /// <summary>
        /// 执行方法异常时触发
        /// </summary>
        /// <param name="ServerAction"></param>
        public virtual void OnExceptionExecuting(IWebSocketServerAction ServerAction)
        {
            
        }

        /// <summary>
        /// 将WebSocketFilterAttribute特性 合并
        /// </summary>
        /// <param name="listArray">特性集合数组</param>
        protected internal static IEnumerable<WebSocketFilterAttribute> GetWebSocketFilterAttribute(params IEnumerable<WebSocketFilterAttribute>[] listArray)
        {
            foreach (var list in listArray)
            {
                foreach (var item in list)
                {
                    yield return item;
                }
            }
        }

    }
}
